package com.hhkj.api.order.controller;

import com.hhkj.admin.common.annotation.Idempotent;
import com.hhkj.api.order.model.req.ApiOrderRefundCancelReq;
import com.hhkj.api.order.model.req.ApiOrderRefundListReq;
import com.hhkj.api.order.model.req.ApiOrderRefundSaveReq;
import com.hhkj.api.order.service.biz.ApiOrderRefundBizService;
import com.hhkj.api.sale.common.session.model.LoginSale;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.login.api.ApiLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ApiOrderRefundController
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/11/3 17:07
 */
@RequestMapping("/api/sale/order/refund")
@RestController
public class ApiOrderRefundController extends BaseController {

    @Autowired
    private ApiOrderRefundBizService refundBizService;

    /** 申请退款 */
    @ApiLogin(LoginSale.class)
    @PostMapping()
    @Idempotent(userTypeCode = Idempotent.UserTypeCode.SALE, timeout = 2)
    public AjaxResult save(@Validated @RequestBody ApiOrderRefundSaveReq req) {
        return refundBizService.save(req) ? AjaxResult.success() : AjaxResult.error();
    }

    /** 取消退款 */
    @ApiLogin(LoginSale.class)
    @PutMapping("/cancel")
    public AjaxResult cancel(@Validated @RequestBody ApiOrderRefundCancelReq req) {
        return refundBizService.cancel(req) ? AjaxResult.success() : AjaxResult.error();
    }

    /** 列表 */
    @ApiLogin(LoginSale.class)
    @PostMapping("/list")
    public TableDataInfo list(@Validated @RequestBody ApiOrderRefundListReq req) {
        return getDataTable(refundBizService.list(req));
    }
}
